#include "ULUI_Help.h"
#include "UL_Global.h"
#include <SDL/sprig.h>

ULUI_Help ULUI_Help::help;

#define HELP_DRAW_AREA_START_X	100
#define HELP_DRAW_AREA_START_Y	100

void ULUI_Help::Init()
{
	AttachEventHandler(this);

	backMenu.SetFont(UL_Global::UnionLottoFont());
	backMenu.SetTitle("回主菜单");
	backMenu.title.SetEncode(FONT_CODE_UTF8);
	backMenu.ShowBoarder(true);
}

void ULUI_Help::CleanUp()
{

}

void ULUI_Help::Pause()
{
}

void ULUI_Help::Resume()
{
}

void ULUI_Help::Update(VSDL_GameEngine *game)
{
}

void ULUI_Help::Draw(VSDL_GameEngine *game)
{
	int fontHeight;
	VSDL_Point msgXY;
	VSDL_Text msg;
	//Draw Rect
	SDL_Surface *destSurf = game->GetSurface();
	VSDL_RGB rgbLine(0, 0, 0);

	UL_Global::UnionLottoShowBg();
	UL_Global::UnionLottoShowTitle();
	backMenu.Blit(destSurf, VSDL_Point(HELP_DRAW_AREA_START_X, HELP_DRAW_AREA_START_Y));

	fontHeight = UL_Global::UnionLottoGetFontHeight();
	
	msgXY.x = HELP_DRAW_AREA_START_X;
	msgXY.y = fontHeight + HELP_DRAW_AREA_START_Y;

	
	UL_Global::UnionLottoShowTip("中将等级与奖金:", msgXY);
	msgXY.y += fontHeight;

	UL_Global::UnionLottoShowPrizeTable(VSDL_Point(msgXY.x, msgXY.y));

	//msgXY.y -= fontHeight;
	msgXY.x += 600;
	SPG_Rect(destSurf, msgXY.x, msgXY.y, destSurf->w - 20, msgXY.y + 2 * fontHeight, rgbLine.GetRGB32(destSurf));
	UL_Global::UnionLottoShowTip("复式投注细节:", msgXY);
	msgXY.y += fontHeight;
	UL_Global::UnionLottoShowTip("sports.sohu.com/s2007/4569/s252484828/", msgXY);
	
	msgXY.y += fontHeight;
	SPG_Rect(destSurf, msgXY.x, msgXY.y, destSurf->w - 20, msgXY.y + 3 * fontHeight + 2, rgbLine.GetRGB32(destSurf));
	msgXY.y++;
	//Show software info
	UL_Global::UnionLottoShowTip("软件制作:    刘亮", msgXY);
	msgXY.y += fontHeight;
	UL_Global::UnionLottoShowTip("软件版本:    v1.0.0", msgXY);
	msgXY.y += fontHeight;
	UL_Global::UnionLottoShowTip("生成时间:    2012-10-23", msgXY);
}

ULUI_Help *ULUI_Help::Instance()
{
	return &help;
}


void __HANDLE_EVENT ULUI_Help::OnKeyDown(SDLKey keysym, unsigned char *keyStates, void *arg)
{
	VSDL_GameEngine *game = reinterpret_cast<VSDL_GameEngine *>(arg);

	if (keyStates[SDLK_ESCAPE]){
		game->PopState();
	}
}

void __HANDLE_EVENT ULUI_Help::OnMouseMove(int button, unsigned char buttonState, int absX, int absY, int relX, int relY, void *arg)
{
	backMenu.SelectedCheck(absX, absY);
}

void __HANDLE_EVENT ULUI_Help::OnMouseDown(int button, unsigned char buttonState, int absX, int absY, void *arg)
{
	VSDL_GameEngine *game = reinterpret_cast<VSDL_GameEngine *>(arg);

	if (backMenu.IsXYInRect(absX, absY)){
		game->PopState();
	}
}

void __HANDLE_EVENT ULUI_Help::OnQuit(void *arg)
{
	VSDL_GameEngine *game = reinterpret_cast<VSDL_GameEngine *>(arg);
}
